<template>
  <div>
    <el-form label-width="120px" label-position="left" :model="searchForm">
      <el-row>
        <el-col :span="8">
          <el-form-item label="所在地区">
            <el-cascader
              v-model="searchForm.area_temp"
              ref="cascader"
              :options="areaOptions"
              :props="defaultProps"
              @change="handleChange(), (searchForm.areaId = areaIds)"
            ></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="房屋名称">
            <el-input v-model="searchForm.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="创建时间">
            <el-date-picker
              v-model="searchForm.createTime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="房屋地址">
            <el-input v-model="searchForm.address"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否是学区房">
            <el-select v-model="searchForm.isSchool">
              <el-option label="全部" :value="''"></el-option>
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态">
            <el-select v-model="searchForm.status">
              <el-option label="全部" :value="''"></el-option>
              <el-option label="下架" :value="1"></el-option>
              <el-option label="上架" :value="2"></el-option>
              <el-option label="已出租" :value="3"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="最小租金">
            <el-input v-model.number="searchForm.minRent"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="最大租金">
            <el-input v-model.number="searchForm.maxRent"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-button @click="onSearch" type="primary">查 询</el-button>
          <el-button @click="reset()">重 置</el-button>
        </el-col>
      </el-row>
    </el-form>
    <hr />
    <el-button type="primary" @click="toAdd">新 增</el-button>
    <page-table
      :data="tableData"
      :total="count"
      :page="pageIndex"
      :pageSize="pageSize"
      ref="pageTable"
      showIndex
      @currentChange="currentChange"
      @sizeChange="sizeChange"
      :loading="loading"
    >
      <el-table-column
        show-overflow-tooltip
        prop="name"
        label="房屋名"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="address"
        label="房屋地址"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="rent"
        label="租金"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="userNickName"
        label="房东昵称"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="areaName"
        label="所在地区"
      ></el-table-column>
      <el-table-column show-overflow-tooltip label="创建时间">
        <template slot-scope="{ row }">
          {{ row.createdAt | timeFilter }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="状态">
        <template slot-scope="{ row }">
          {{
            row.status == 1
              ? "下架"
              : row.status == 2
              ? "上架"
              : row.status == 3
              ? "已出租"
              : "暂存"
          }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="是否是学区房">
        <template slot-scope="{ row }">
          {{ row.isSchool ? "是" : "否" }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{ row }">
          <el-button
            type="text"
            v-if="$store.getters.uid == row.uid"
            @click="toRemove(row.id)"
            :disabled="row.status != 1"
            >删除
          </el-button>
          <el-button
            type="text"
            v-if="$store.getters.uid == row.uid"
            :disabled="row.status != 1"
            @click="toEdit(row.id)"
            >修改
          </el-button>
          <el-button type="text" @click="toDetail(row.id)">详情</el-button>
          <el-button
            type="text"
            v-if="
              $store.getters.uid == row.uid &&
                (row.status == 4 || row.status == 1)
            "
            @click="toPushOn(row.id)"
            >上架
          </el-button>
          <el-button
            type="text"
            v-if="$store.getters.uid == row.uid && row.status == 2"
            @click="toPushOff(row.id)"
            >下架
          </el-button>
        </template>
      </el-table-column>
    </page-table>
    <post-dialog @cancel="cancel" :dialogVisible="dialogVisible" :opId="opId" />
    <detail-dialog
      @cancel="cancel1"
      :dialogVisible="dialogVisible1"
      :opId="opId"
    />
  </div>
</template>

<script>
import getAreaList from "../../../mixins/getAreaList";
import initData from "../../../mixins/initData";
import PostDialog from "../components/postDialog";
import DetailDialog from "../components/detailDialog";

export default {
  components: { DetailDialog, PostDialog },
  name: "houseManage",
  mixins: [getAreaList, initData],
  data() {
    return {
      getUrl: "/api/house/house",
      searchForm: {
        name: "",
        createTime: "",
        address: "",
        areaId: "",
        minRent: "",
        maxRent: "",
        isSchool: "",
        status: ""
      }
    };
  }
};
</script>

<style scoped></style>
